package com.easylinkin.linkappapi.lobar.controller.app;

import com.easylinkin.linkappapi.lobar.dto.UserGateDTO;
import com.easylinkin.linkappapi.lobar.dto.UserRecordDTO;
import com.easylinkin.linkappapi.lobar.dto.app.AppUserGateDTO;
import com.easylinkin.linkappapi.lobar.dto.app.LobarUserDTO;
import com.easylinkin.linkappapi.lobar.entity.UserClock;
import com.easylinkin.linkappapi.lobar.entity.UserRecord;
import com.easylinkin.linkappapi.lobar.service.UserClockService;
import io.swagger.annotations.Api;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

/**
 * @author: kan yuanfeng
 * @Date: 2020/11/04 11:42
 * @Description: app端考勤记录
 */
@RestController
@RequestMapping("appUserClock")
@Api(tags = "app端考勤记录")
public class AppUserClockController {

  @Autowired
  private UserClockService userClockService;
  /**
   * 查询个人月考勤记录
   */
  @GetMapping("mouth/{userId}")
  public RestMessage getUserMouth(@PathVariable("userId")String userId, String mouth){
    List<UserRecord> userRecords = userClockService.getUserMouth(userId,mouth);
    return RestBuilders.successBuilder().data(userRecords).build();
  }

  /**
   * 根据实际查询当天打卡记录
   */
  @GetMapping("day/{userId}")
  public RestMessage getUserDay(@PathVariable("userId")String userId, String time)
      throws ParseException {
    SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");
    List<UserClock> userClocks = userClockService.getUserDay(userId,sdf.parse(time));
    return RestBuilders.successBuilder().data(userClocks).build();
  }

  /**
   * 柱状图(7天考勤统计)
   */
  @GetMapping("sevenDay")
  public RestMessage getSevenDay(){
    List<LobarUserDTO> lobarUserDTOS = userClockService.getSevenDay();
    return RestBuilders.successBuilder().data(lobarUserDTOS).build();
  }

  /**
   *app参建单位统计
   */
  @GetMapping("company")
  public RestMessage getCompany(String time) throws ParseException {
    SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");
    Date date = sdf.parse(time);
    List<AppUserGateDTO> appUserGateDTOS = userClockService.getCompany(date);
    return RestBuilders.successBuilder().data(appUserGateDTOS).build();
  }

  /**
   *app班组统计
   */
  @GetMapping("group/{companyProjectId}")
  public RestMessage getGroup(@PathVariable("companyProjectId")String companyProjectId, String time) throws ParseException {
    SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");
    Date date = sdf.parse(time);
    List<AppUserGateDTO> appUserGateDTOS = userClockService.getGroup(companyProjectId,date);
    return RestBuilders.successBuilder().data(appUserGateDTOS).build();
  }

  /**
   *app人员统计
   */
  @GetMapping("user")
  public RestMessage getUser(String companyProjectId,String groupId, String time,Integer recordType) throws ParseException {
    SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");
    Date date = sdf.parse(time);
    List<UserRecordDTO> userGates = userClockService.getUser(companyProjectId,groupId,date,recordType);
    return RestBuilders.successBuilder().data(userGates).build();
  }
}
